﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATEGo
{
    //———————————————————————【进度】————————————————————————
    public partial class Executor
    {
        /// <summary>
        /// ProgressBar设置总值，并初始化
        /// </summary>
        private void Pb_InitialValue(int max)
        {
            if (This_ProgressBar == null)
            {
                return;
            }
            Pb_Count = max + 1;
            Action act = () =>
            {
                This_ProgressBar.Maximum = 100;
                This_ProgressBar.Value = 1;
                Prg_ShowValue("1%");
            };
            This_Form.Invoke(act);
        }
        /// <summary>
        /// ProgressBar增加一次值
        /// </summary>
        private void Pb_Add()
        {
            if (This_ProgressBar == null)
            {
                return;
            }
            Action act = () =>
            {
                if (This_ProgressBar.Value < This_ProgressBar.Maximum)
                {
                    This_ProgressBar.Value += 100 / Pb_Count;
                    Prg_ShowValue(This_ProgressBar.Value.ToString() + "%");
                }
            };
            This_Form.Invoke(act);
        }
        /// <summary>
        /// 出现问题时，ProgressBar状态
        /// </summary>
        private void Pb_Error()
        {
            if (This_ProgressBar == null)
            {
                return;
            }
            Action act = () =>
            {
                This_ProgressBar.Value = 0;
                Prg_ShowValue("ERROR");
            };
            This_Form.Invoke(act);
        }

        /// <summary>
        /// progressbar结束
        /// </summary>
        private void Pb_End()
        {
            if (This_ProgressBar == null)
            {
                return;
            }
            Action act = () =>
            {
                if (This_ProgressBar.Value < This_ProgressBar.Maximum)
                {
                    This_ProgressBar.Value = 100;
                    Prg_ShowValue("100%");
                }
            };
            This_Form.Invoke(act);
        }
    }
}
